var MongoClient = require("mongodb").MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, { useNewUrlParser: true }, function (err, db) {
  if (err) throw err;
  var dbo = db.db("toolsDb");
  // var myobj = { name: "菜鸟教程", url: "www.runoob" };
  var userObj = {
    userName: "1933851647@qq.com",
    password: "123321",
    avatar:
      "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1641925520,3949603965&fm=26&gp=0.jpg",
    description: "波波是个瘦子",
    powerType: "1",
    isManager: "1",
    registrationTime: "",
    lastLoginTime: "",
  };

  dbo.collection("user").insertOne(userObj, function (err, res) {
    if (err) throw err;
    console.log("文档插入成功");
    // db.close();
  });

  var toolsObj = {
    title: "json解析工具",
    icon:
      "https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1641925520,3949603965&fm=26&gp=0.jpg",
    description: "波波是个瘦子",
    url: "1",
    createTime: "1",
  };

  dbo.collection("tools").insertOne(toolsObj, function (err, res) {
    if (err) throw err;
    console.log("文档插入成功");
    // db.close();
  });
  var dbo = db.db("toolsDb");


  var powerObj = {
    name: "A级权限",
    type: "1",
    eableToolsID: "1",
  };

  dbo.collection("power").insertOne(powerObj, function (err, res) {
    if (err) throw err;
    console.log("文档插入成功");
    // db.close();
  });

  var powerObj = {
    name: "A级权限",
    type: "1",
    eableToolsID: "2",
  };

  dbo.collection("power").insertOne(powerObj, function (err, res) {
    if (err) throw err;
    console.log("文档插入成功");
    // db.close();
  });


var powerObj = {
    name: "A级权限",
    type: "1",
    eableToolsID: "3",
  };

  dbo.collection("power").insertOne(powerObj, function (err, res) {
    if (err) throw err;
    console.log("文档插入成功");
    db.close();
  });


});
